package main

import (
	"fmt"
	"os"
	"path/filepath"
)

func printDirTree(path string, indent string, isLast bool) {
	fmt.Print(indent)
	if isLast {
		fmt.Print("└── ")
		indent += "    "
	} else {
		fmt.Print("├── ")
		indent += "│   "
	}
	fmt.Println(filepath.Base(path) + string(os.PathSeparator))

	fileInfos, err := os.ReadDir(path)
	if err != nil {
		fmt.Println(err)
		return
	}

	for i, fi := range fileInfos {
		isLastFile := i == len(fileInfos)-1
		if fi.IsDir() {
			printDirTree(filepath.Join(path, fi.Name()), indent, isLastFile)
		} else {
			fmt.Print(indent)
			if isLastFile {
				fmt.Print("└── ")
			} else {
				fmt.Print("├── ")
			}
			fmt.Println(fi.Name())
		}
	}
}

func main() {
	if len(os.Args) < 2 {
		fmt.Println("Usage: go run main.go <path>")
		return
	}

	path := os.Args[1]

	info, err := os.Stat(path)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	if !info.IsDir() {
		fmt.Println(path, "is not a directory")
		return
	}

	fmt.Println(path)
	printDirTree(path, "", true)
}
